<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="com.carrentalssm.controller.LoginController"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@page import="com.carrentalssm.service.CarListService"%>
<%@page import="com.carrentalssm.entity.CarList"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>小彭租车后台管理</title>

<script type="text/javascript" src="<%=request.getContextPath() %>/frame/jquery-3.6.0.min.js"></script>
<link rel="stylesheet" href="<%=request.getContextPath() %>/frame/bootstrap-3.4.1-dist/css/bootstrap.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/frame/bootstrap-3.4.1-dist/js/bootstrap.js"></script>
<link type="text/css" rel="stylesheet" href="css/common.css">
<style type="text/css">
	body{
		background-image: url("images/background.jpg");
		overflow: hidden;
	}
	.login-div{
		background: rgba(217, 237, 247);
		width: 600px;
		box-sizing: border-box;
		margin: 0px auto;
		padding: 20px 40px;
	}
	.login-title{
		text-align: center;
		font-size: 30px;
	}
	.form-item{
		box-sizing: border-box;
		width: 100%;
		height: 35px;
		margin-top: 15px;
		padding: 0px 5px;
	}
</style>
</head>
<body>
	<%
	Object loginUser = request.getSession().getAttribute("user");
	if (loginUser == null) {
		response.sendRedirect(request.getContextPath()+"/login.jsp");
		return;
	}
	%>

	<div class="head">
		<div class="head-content">
			<h2>小彭租车！</h2>
			<a href="admin.jsp">首页</a>

			<a href="adminUserList.jsp">用户管理</a>
			<a href="logout">退出</a>
		</div>
	</div>
	<div class="main">
		<div class="main-content">
			<a href="adminCarListAdd.jsp"><button class="select-button btn btn-primary">添加汽车</button></a>
			<table class="table table-hover">
				<thead>
					<tr>
						<th>编号</th>
						<th>型号</th>
						<th>数量</th>
						<th>单价</th>
						<th>添加时间</th>
						<th>添加人</th>
						<th>操作</th>
					</tr>
				</thead>
				<tbody>
					<%
						WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
						CarListService carListService = (CarListService) context.getBean("carListService");
						List<CarList> carLists = carListService.selectAll();
						for (CarList carList : carLists) {
							out.print("<tr>");
							out.print("<td>" + carList.getId() + "</td>");
							out.print("<td>" + carList.getModel() + "</td>");
							out.print("<td>" + carList.getNumber() + "</td>");
							out.print("<td>" + carList.getPrice() + "</td>");
							out.print("<td>" + carList.getCreateDatetime() + "</td>");
							out.print("<td>" + carList.getCreateUsername() + "</td>");
							out.print("<td>");
							out.print("<a href='adminCarListUpdate.jsp?id=" + carList.getId() + "'>修改</a>");
							out.print(" <a href='" + request.getContextPath() +"/carList/delete?id=" + carList.getId() + "'>删除</a>");
							out.print("<td>");
							out.print("</tr>");
						}
					%>
				</tbody>
			</table>
		</div>
	</div>
</body>
</html>